from pathlib import Path

# 写入一行
                                            #指定文件已存在，wirte_text()删除其中内容
path = Path('day15/programming.txt')        #并将新内容写入
path.write_text("I love programming.")
path.write_text(str(3.1415926))             #Python只能将字符串写入文本文件

# 写入多行
contents = "I love programming.\n"
contents += "I love creating new games.\n"
contents += "I also love working with data.\n"
path = Path('day15/programming_2.txt')
path.write_text(contents)